package com.gcph.zhuoba.main.Fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.gcph.zhuoba.R;
import com.gcph.zhuoba.app.GcphApplication;
import com.gcph.zhuoba.main.activitys.HelperActualActivity;
import com.gcph.zhuoba.main.activitys.TeachingMainActivity;
import com.gcph.zhuoba.player.activitys.OnlineHelpActivity;
import com.gcph.zhuoba.util.NetUtil;

public class HelperFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View contactsLayout = null;
		if(getResources().getString(R.string.constant_tutor).equals(GcphApplication.getInstance().getSpUtil().getUserType()))
		{
			contactsLayout = inflater.inflate(R.layout.layout_helper_tutor,container, false);
		}else
		{
			contactsLayout = inflater.inflate(R.layout.layout_helper_player,container, false);
		}
		
		ImageView btnActual=(ImageView)contactsLayout.findViewById(R.id.btn_actual);
		btnActual.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(),HelperActualActivity.class);
				startActivity(intent);
			}
		});
		
		
		if(getResources().getString(R.string.constant_player).equals(GcphApplication.getInstance().getSpUtil().getUserType()))
		{
			ImageView btnOnlinehelp=(ImageView)contactsLayout.findViewById(R.id.btn_online_help);
			btnOnlinehelp.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					//先校验网络
					if(NetUtil.isNetConnected(v.getContext()))
					{
						Intent intent = new Intent(getActivity(),OnlineHelpActivity.class);
						startActivity(intent);
					}
				}
			});
		}else
		{
			ImageView btnMaking=(ImageView)contactsLayout.findViewById(R.id.btn_making);
			btnMaking.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					//先校验网络
					if(NetUtil.isNetConnected(v.getContext()))
					{
						Intent intent = new Intent(getActivity(),TeachingMainActivity.class);
						startActivity(intent);
					}
				}
			});
		}
		
		//先校验网络
		if(!NetUtil.isNetConnected(inflater.getContext()))
		{
			Toast.makeText(inflater.getContext(), "没有可用的网络，请先设置网络连接", Toast.LENGTH_LONG).show();
		}
		
		return contactsLayout;
	}

}
